## Ryan Copus and Ryan Hübert
## Measuring How Much Judges Matter for Case Outcomes
## Journal of Law and Courts

# Note to reader: please review the README for important information about 
# software and other requirements

################################################################################
# USER-SPECIFIED VARIABLES TO BE PASSED INTO THE ENVIRONMENT
################################################################################

# Define environment flags for use in the replication scripts
env <- new.env()

## Do you want to resume a partially completed run of the scripts (e.g. if there was an error)?
env$resume <- FALSE # Set this to TRUE if you want to resume partially completed run

## Do you want to save (and potentially over-write) tables and figures to `Outputs/` directory?
env$to.save <- TRUE # Set this to TRUE if you want to save

## Do you want to limit the memory that h2o uses for estimating models?
env$mem <- 64 # Measured in GB --- can increase or decrease as desired

# How many cores of your computer do you want to use to run h2o models?
env$ncores <- parallel::detectCores() # this will use use all your computer's cores

################################################################################
# DEFINE THE LIST OF REPLICATION SCRIPTS TO RUN IN ORDER
################################################################################

scripts <- c(
  "Code/1.CalculateDeviance.R",
  "Code/2.GeneratePRQs.R",
  "Code/3.CheckRandomization.R",
  "Code/4.FiguresTables.R"
)

################################################################################
# EXECUTE EACH SCRIPT IN ORDER
################################################################################

# Define an 80 length divider line
divider <- paste0(rep("=",80), collapse="")

# Iterate over scripts and run them
for(script in scripts){
  message(paste0(divider,"\n", "Now running: ", script,"\n", divider))
  source(here::here(script), local = env, echo = FALSE)
}